<?php
/**
 * Breadcrump array 
 */
function cp_get_breadcrumb() {
	global $post;
	//exit(var_dump($post));
	$bc = array();
	switch(true){
		case is_home(): $bc[] = get_bloginfo('name'); break;
		case ($post->post_type == 'page'):
			//exit('page'); 
			$bc[] =  get_page($post->ID);
		case is_tax():
			global $taxonomy, $term;
			$term_object = get_term_by('slug',$term, $taxonomy);
			$bc[] = $term_object->name;
	}
	return $bc;
}

// Code for my main menu
function cp_render_sidebar_menu(){
	wp_nav_menu( array('theme_location' => 'sidebar_menu',  
	'container' => 'div', 
	'container_id' => 'navleft',
	'container_class' => '',
	'menu_class' =>  'navlist'));
}


function cp_renderer_path_audio(){
	global $post;
	$uploads = wp_upload_dir();
	$aMeta = get_post_meta($post->ID,'_metabox_legrandmix',true);
	$path_audio = $aMeta['legrandmix_path_audio'];
	return $uploads['baseurl'] . '/'. trim($path_audio,'/');
}

// Code render audio player
function cp_render_player(){
?>
<div id="lecteur">
	<div id="controls">
		<img id="play" src="<?php bloginfo('template_url'); ?>/images/play.png" alt="play" title="Lecture" onclick="bouton_play();" />
		<img id="next" src="<?php bloginfo('template_url'); ?>/images/next.png" alt="suivant" title="Titre suivant" onclick="bouton_next();" />
		<img id="volume" src="<?php bloginfo('template_url'); ?>/images/volume.png" alt="volume" title="100" onmousedown="clic('vol', event);" onmousemove="move('vol', event);" />
	</div>
	<div id="avancement">
		<div id="test"><img id="barre" src="<?php bloginfo('template_url'); ?>/images/barre.png" onmousedown="clic('barre', event);" onmousemove="move('barre', event);" /><br />
		<img id="chargement" src="<?php bloginfo('template_url'); ?>/images/none.png" />
	</div>
</div>
<div id="tagid3"></div>
<?php
}

function cp_render_single_shares(){
?>
<a target="blank" title="Partager '<?php the_title()?>' sur FaceBook" href="http://www.facebook.com/share.php?u=<?php the_permalink()?>&t=<?php urlencode(the_title())?>">
	<img src="<?php bloginfo('template_url');?>/images/facebook.png"/>
</a>
<a target="blank" title="Partager '<?php the_title()?>' sur MSN-Live" href="http://favorites.live.com/quickadd.aspx?url=<?php the_permalink()?>&title=<?php urlencode(the_title())?>">
	<img src="<?php bloginfo('template_url');?>/images/live.png"/>
</a>
<a target="blank" title="Partager '<?php the_title()?>' sur Myspace" href="http://www.myspace.com/Modules/PostTo/Pages/?t=<?php urlencode(the_title())?>&c=<?php the_permalink()?>">
	<img src="<?php bloginfo('template_url');?>/images/myspace.png"/>
</a>
<a target="blank" title="Partager '<?php the_title()?>' sur Google Bookmarks" href="http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk=<?php the_permalink()?>&title=<?php urlencode(the_title())?>">
	<img src="<?php bloginfo('template_url');?>/images/google.png"/>
</a>
<?php
}



/**
 * Display notes 
 */
function cp_render_notes(){
	echo
	'<p class="first">Ceci peut vous intéresser :</p> 
	 <a href="http://www.karzoo.eu" target="blank"><img src="'. get_bloginfo('home') . '/wp-content/uploads/2009/06/karzoo.jpg" width="190" /></a>
	 <a href="http://www.skyscanner.fr/" target="blank"><img src="'. get_bloginfo('template_url').'/images/projet03.jpg" width="190" height="50"/></a>
	 <a href="http://www.plurio.org/" target="blank"><img src="'. get_bloginfo('home') . '/wp-content/uploads/2009/06/plurio-5.jpg" width="190" /></a>';
}

/**
 * Display flux 
 */
function cp_render_flux(){
	echo
	'<ul class="xml">
	<li><a target="blank" class="atom" href="http://feeds2.feedburner.com/carbonpaper">Inscription à tous les posts</a></li>
	</ul>';
}


/**
 * Display Colophon 
 */
function cp_render_colophon(){
	echo
	'<ul class="colophon"> 
		<li><a href="http://www.gentoo.org" class="gen" target="blank">Serveur Linux Gentoo</a></li> 
		<li><a href="http://www.wordpress.org" class="wp" target="blank">Publication wordpress.org</a></li> 
		<li><a href="http://www.ovh.com" class="ovh"  target="blank">Hébergement OVH</a></li> 
		<li><a href="http://creativecommons.org/licenses/by-nc-sa/2.0/fr" class="cc"  target="blank"> License Creative Commons</a></li> 
	</ul>';
}


/**
 * Display taxonomy with image. 
 */
function cp_render_taxonomy_terms($taxonomy){
	$taxonomy_terms = get_terms($taxonomy, 'orderby=name&hide_empty=0');
	$taxonomy_object = get_taxonomy($taxonomy);
	$taxonomy_path = $taxonomy_object->rewrite['slug'] ? $taxonomy_object->rewrite['slug'] : $taxonomy_object->name; 
	foreach ($taxonomy_terms as $term)
		echo
		'<h4>'. $term->name .'</h4>
		<a href="'. get_bloginfo('home') . '/' . $taxonomy_path . '/'. $term->slug .'">
		<img src="'. get_bloginfo('template_url') . '/images/' . $term->taxonomy . '-'. $term->slug . '.jpg" width="190"/></a>
		<p>' . $term->description . '</p>';
}


/**
 * Display taxonomy inline. 
 */
function cp_render_taxonomy_terms_inline($post, $excluded_taxonomy = ''){
	// Get taxonomies of the post_type
	$taxonomies = get_taxonomies();
	$terms_exist = false;
	$html = '<div class="reaction_buttons">'; 
	foreach ($taxonomies as $taxonomy){
		if ($taxonomy != $excluded_taxonomy){
			// Get terms of the taxonomy 
			$terms = wp_get_post_terms($post->ID,$taxonomy);
			// Sort terms by parent id;
			$parents = array();
			foreach( $terms as $term ) $parents[] = $term->parent;
			array_multisort($parents, $terms);
			// List terms
			foreach ($terms as $term){
				$terms_exist = true;
				$taxonomy_object = get_taxonomy($term->taxonomy);
				// Define the taxonomy label of the term:
				switch ($term->taxonomy) {
					case 'category':
						if ($term->parent == '0')
							$label = 'Classé dans: ';		
						else 
							$label = 'Rubrique: ';
					break;
					default: $label = $taxonomy_object->labels->singular_name . ': ';
				//var_dump($taxonomy_object); echo '<br>'; continue;
				}
				// Define the taxonomy path of the term:
				$taxonomy_path = $taxonomy_object->rewrite['slug'] ? $taxonomy_object->rewrite['slug'] : $taxonomy_object->name; 
				// Display the taxonomy term inline:
				$html .= '<a class="reaction_button" href="'. get_bloginfo('home') . '/' . $taxonomy_path . '/'. $term->slug .'">' . $label . $term->name . '</a>';
			}
		}
	}
	$html .= '</div>';
	if ($terms_exist) 
		echo $html;  
//	if ( function_exists( 'reaction_buttons_html' ) ) 
//		echo reaction_buttons_html(); 	
}


/**
 * Prints the pagination. Checks whether the WP-Pagenavi plugin is installed and if so, calls
 * the function for pagination of this plugin. If not- shows prints the previous and next post links.
 */
function cp_render_pagination(){
if(function_exists('wp_pagenavi')){
	wp_pagenavi();
}else{
echo
'<div id="blog_nav_buttons" class="navigation">
	<div class="alignleft">'. previous_posts_link('<span>&laquo;</span>Précédent').
'</div>
<div class="alignright">'. next_posts_link('Suivant<span>&raquo;</span>'). 
'</div>
</div>';
	} 
}
?>